<template>
  <div class="g-dialog-panel confirm">
    <div class="g-dialog-title">
      <span>Confirm Swap</span>
      <div class="g-clickable close" @click="close">
        <i class="iconfont icon-close"></i>
      </div>
    </div>
    <div class="content">
      <div class="token">
        <img :src="from.icon" />
        <span>{{ inAmount }}</span>
        <div>
          <span>{{ from.symbol }}</span>
        </div>
      </div>
      <div class="arrow">
        <i class="iconfont icon-arrow-down2"></i>
      </div>
      <div class="token">
        <img :src="to.icon" />
        <span>{{ outAmount }}</span>
        <div>
          <span>{{ to.symbol }}</span>
        </div>
      </div>
      <div class="tips">
        <p>
          Output is estimated. you receive at last
          <span>{{ minOutAmount }} {{ to.symbol }}</span> or transaction will
          revert.
        </p>
      </div>
      <SwapLabel name="Price" :value="price" />
      <SwapLabel name="Maximum Sold" help="1" value="10 USDT" />
      <SwapLabel
        name="Price Impact"
        help="1"
        value="< 0.01%"
        :ext-class="{ blue: true }"
      />
      <SwapLabel name="Liquidity Provider Fee" help="1" value="0.03 USDT" />
      <div class="g-clickable button" @click="$emit('confirm')">
        <span>Confirm Swap</span>
      </div>
    </div>
  </div>
</template>

<script>
import SwapLabel from "@/components/SwapLabel";
import { mapState } from "vuex";

export default {
  components: {
    SwapLabel,
  },
  props: {
    inAmount: {
      type: [Number, String],
      default: 0,
    },
    outAmount: {
      type: [Number, String],
      default: 0,
    },
    minOutAmount: {
      type: [Number, String],
      default: 0,
    },
  },
  computed: {
    ...mapState({
      from: (state) => state.from,
      to: (state) => state.to,
      account: (state) => state.account,
    }),
    price() {
      if (this.outAmount && this.inAmount) {
        const amount = this.outAmount / this.inAmount;
        return `${amount} ${this.from.symbol} Per ${this.to.symbol}`;
      }
      return "--";
    },
  },
  methods: {
    close() {
      this.$emit("close");
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  padding-top: 40px;
}

.arrow {
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin: 12px 0;

  i {
    font-size: 20px;
    margin-left: 5px;
    color: var(--color-content);
  }
}

.token {
  display: grid;
  align-items: center;
  grid-template-columns: 40px 1fr 1fr;

  img {
    width: 30px;
    border: 1px solid var(--card);
    box-sizing: border-box;
    border-radius: 15px;
  }

  span {
    font-size: 16px;
    font-family: "Roboto Black";
  }

  div {
    display: flex;
    align-items: center;
    justify-content: flex-end;

    span {
      font-size: 20px;
    }
  }
}

.tips {
  margin-top: 30px;
  padding-bottom: 10px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-content);
  font-family: "Roboto Regular";

  span {
    color: var(--color);
    font-family: "Roboto Bold";
  }
}
.button {
  height: 60px;
  font-size: 18px;
  color: var(--color-dark);
  background-image: var(--button-bg);
  transition: all 0.3s ease;
  border-radius: 30px;
  margin-top: 30px;

  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;

  span {
    font-size: 15px;
    font-family: "Roboto Bold";
    color: var(--color-dark);
  }
}
</style>
